layui.use('table', function(){
  var table = layui.table;
  
  //监听表格复选框选择
  table.on('checkbox(demo)', function(obj){
    console.log(obj)
  });
 
//监听单元格编辑
  table.on('edit(idTest)', function(obj){
    var value = obj.value //得到修改后的值
    ,data = obj.data //得到所在行所有键值
    ,field = obj.field; //得到字段
    layer.msg('[ID: '+ data.id +'] ' + field + ' 字段更改为：'+ value);
  });
  
  
  
  /**
   * 从地址栏传值的代码
   * @param param
   * @returns
   */
  function getParameter(param){
  	var query = window.location.search;
  	var iLen = param.length;
  	var iStart = query.indexOf(param);
  	if (iStart == -1)
  		return "";
  	iStart += iLen + 1;
  	var iEnd = query.indexOf("&", iStart);
  	if (iEnd == -1)
  		return query.substring(iStart);
  	return query.substring(iStart, iEnd);
  }
  
  
//监听工具条
  table.on('tool(demo)', function(obj){
    var da = obj.data;
    //删除
    if(obj.event === 'return'){
    	layer.open({
  		  type: 2, //设置为iframe
  		  area: ['90%', '70%'],
		  offset: '5%',
  		  content: ['../../pages/ListenReturn/purchaseDetaisl.html?id='+da.sellId, 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
  		  ,end: function(){
  		  }
  		  ,success: function(layero, index){
  			  iframe.load();
  		  }
  	  });
    //修改
    } else if(obj.event === 'detail'){
    	layer.open({
    		  type: 2, //设置为iframe
    		  area: ['70%', '80%'],
    		  offset: '5%',
    		  content: ['../../pages/ListenSell/sellDetail.html?id='+da.sellId, 'no'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    		  ,end: function(){ 
    		  }
    		  ,success: function(layero, index){
    			  
    			  iframe.load();
    		  }
    	  }); 
    }
  });
  //表单重载
  var $ = layui.$, active = {
		    reload: function(){
		      var sellId = $('#sellId');
		      //执行重载    查询
		      table.reload('idTest', {
		        page: {
		          curr: 1 //重新从第 1 页开始
		        }
		        ,where: {
		        	sellId: sellId.val()
		        }
		      });
		    }
		  };
  active['reload'] ? active['reload'].call(this) : '';
  $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});